package com.dx.as.upload;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by jwaoo on 2017/7/18.
 */

public class DownloadManager {
    private static Map<Integer,DownloadInfo> map = new HashMap<>();

    public static void addDownloadListener(int msgId, OnDownloadListener listener){
        if (!map.containsKey(msgId)){
            DownloadInfo info = new DownloadInfo();
            info.setOnDownloadListener(listener);
            map.put(msgId,info);
        }else {
            map.get(msgId).setOnDownloadListener(listener);
        }
    }

    public static void removeDownloadListener(int msgId){
        map.get(msgId).setOnDownloadListener(null);
    }

    public static void removeDownload(int msgId){
        map.remove(msgId);
    }

    public static DownloadInfo getDownloadObject(int msgId){
        DownloadInfo downloadInfo = map.get(msgId);
        if (downloadInfo == null) {
            downloadInfo = new DownloadInfo();
            map.put(msgId,downloadInfo);
        }
        return downloadInfo;
    }

    public static void addDownload(int msgId,DownloadInfo downloadInfo){
        if (!map.containsKey(msgId))
            map.put(msgId,downloadInfo);
    }
}
